using System;
using System.Threading.Tasks;
using Furion.DatabaseAccessor;
using Furion.DependencyInjection;

namespace WebSMS;

public class UserPostLinksService : ITerPostUser,ITransient
{
    private readonly IRepository<UserPostLinks> _repo;
    public UserPostLinksService(IRepository<UserPostLinks> repository)
    {
        _repo = repository;
    }
    public async Task<bool> AddUserToPost(Guid userId, Guid postId)
    {
        await _repo.InsertNowAsync(new UserPostLinks(){Id = Guid.NewGuid(), UserId = userId,PostId = postId,CreatedTime = DateTime.Now});
        return true;
    }

    public async Task<bool> RemoveUserForPost(Guid postId)
    {
        var queryable = await _repo.FirstOrDefaultAsync(u => u.PostId == postId && u.UserId != Guid.Empty );
        if(queryable != null)
        {
            return true;
        }
        return false;
    }
}